package com.example.bookkeeping1220.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.bookkeeping1220.R;
import com.example.bookkeeping1220.db.AchievementBean;
import com.example.bookkeeping1220.db.HeadportraitBean;

import java.util.List;

public class HeadportraitAdapter extends BaseAdapter {
    Context context;
    List<HeadportraitBean>mDatas;
    LayoutInflater layoutInflater;

    public HeadportraitAdapter(Context context){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
    }

    public HeadportraitAdapter(Context context, List<HeadportraitBean> mDatas) {
        this.context = context;
        this.mDatas = mDatas;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int i) {
        return mDatas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    class ViewHolder{
        public ImageView headIv;
        public TextView headTv;
        ViewHolder(View view){
            headIv = view.findViewById(R.id.item_head_gv_iv);
            headTv = view.findViewById(R.id.item_head_gv_title);
        }
    }
    @Override
    public View getView(int i, View convertView, ViewGroup parent) {
        HeadportraitAdapter.ViewHolder holder = null;
        if (convertView == null){
            convertView = layoutInflater.inflate(R.layout.item_headportrait_gv,parent,false);
            holder = new HeadportraitAdapter.ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (HeadportraitAdapter.ViewHolder) convertView.getTag();
        }
        HeadportraitBean bean = mDatas.get(i);
        holder.headTv.setText(bean.getHeadName());
        holder.headIv.setImageResource(bean.getsImageId());
        return convertView;
    }
}

